package com.fish.web.user;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang.xwork.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.fish.common.constant.Constant;
import com.fish.common.constant.QueryPage;
import com.fish.common.web.BaseAction;
import com.fish.service.user.MenusService;
import com.fish.user.po.Menus;

public class MenusAction extends BaseAction {
	private static final long serialVersionUID = 3842612461009160944L;
	private static final Log loger = LogFactory.getLog(MenusAction.class);
	private MenusService menusService;
	private Menus menus = new Menus();
	private List<Menus> menusList = new ArrayList<Menus>();
	private QueryPage queryPage = new QueryPage();
	
	public String goToMenus(){
		 return SUCCESS;
	}
	public String goToMenusList(){
		Long count = menusService.queryMenusCountByObject(menus);
		if(count > 0){
			queryPage = new QueryPage(count, Constant.DEFAULT_PAGE_SIZE, queryPage.getCurPage());
		}
		
		menusList = menusService.queryMenusByObject(menus,queryPage);
		return SUCCESS;
	}

	public String viewMenusInfo(){
		if(StringUtils.isNotBlank(menus.getMenuId())) {
			menus = menusService.queryMenusByPrimaryKey(menus.getMenuId());
		}
		 return SUCCESS;
	}
	
	public String saveMenus(){
		try {
			if(StringUtils.isBlank(menus.getMenuId())) {
				menus.setMenuId(this.getNewUUID());
				menus.setCreateTime(new Date());
				menus.setUpdateTime(new Date());
				menusService.addMenus(menus);
			} else {
				menus.setUpdateTime(new Date());
				menusService.updateMenus(menus);
			}
		} catch (Exception e) {
			loger.debug("保存权限有错！");
			loger.debug(e);
		}
		 return goToMenusList();
	}
	
	public Menus getMenus() {
		return menus;
	}
	
	public void setMenus(Menus menus) {
		this.menus = menus;
	}
	
	public void setMenusService(MenusService menusService) {
		this.menusService = menusService;
	}
	
	public List<Menus> getMenusList() {
		return menusList;
	}
	public QueryPage getQueryPage() {
		return queryPage;
	}
	public void setQueryPage(QueryPage queryPage) {
		this.queryPage = queryPage;
	}
	public void setMenusList(List<Menus> menusList) {
		this.menusList = menusList;
	}
	
	
}